<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <title>编辑采购单</title>
    <script src="/static/common/js/jquery-1.11.1.min.js" type="text/javascript"></script>
    <link rel="stylesheet" href="/static/admin/layui/css/layui.css" media="all">
</head>
<body>
<div class="layui-form" style="margin-top: 5px;">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">进货日期</label>
            <div class="layui-input-inline">
                <input type="text" name="purchasetime" id="purchasetime" lay-verify="purchasetime" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">供货单位</label>
            <div class="layui-input-inline">
                <select id="supplier" lay-filter="myselect" name="myselect" lay-verify="required" lay-search="myselect">


                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">应付金额</label>
            <div class="layui-input-inline">
                <input type="text" name="payment"  placeholder="应付金额" class="layui-input" id="payment" readonly>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">价格等级</label>
            <div class="layui-input-inline">
                <select id="grade" lay-filter="grade" name="grade" lay-verify="required" lay-search="grade">
                    <option value="1">默认价</option>
                    <option value="2">记忆价</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">付现金额</label>
            <div class="layui-input-inline">
                <input type="text" name="payamount" placeholder="请输入付现金额" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-inline">
                <input type="text" name="remark"  placeholder="请填写备注" class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">总金额</label>
            <div class="layui-input-inline">
                <input type="text" name="summoney" disabled="true" placeholder="采购总金额" autocomplete="off" class="layui-input" readonly>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">优惠金额</label>
            <div class="layui-input-inline">
                <input type="text" name="favorable"   placeholder="请输入优惠金额"  autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
</div>
<div style="margin: 4px;font-size: 20px;">商品列表</div>
<button class="layui-btn layui-btn-sm" style="margin: 5px;"><i class="layui-icon"></i></button>
<table id="autSysLog" lay-filter="test"></table>

<script src="/static/admin/layui/layui.js"></script>
<script type="text/javascript" src="/static/common/js/dateFormat.js"></script>
<script>
    $(function () {
        initSelect();
    });
    layui.use(['form', 'jquery',  'table','laydate'], function(){
        var table = layui.table,
                form=layui.form,
                layer=layui.layer,
                laydate=layui.laydate;

        //日期时间选择器
        laydate.render({
            elem: '#purchasetime'
            ,value: new Date()
            ,isInitValue: true
        });
        //第一个实例
        table.render({
            elem: '#autSysLog'
            ,height: 500
            ,url: '/purchase/selectAll' //数据接口
            ,page: true //开启分页
            ,cols: [[ //表头
                {type:'checkbox'}
                ,{type:'numbers'}
                ,{field: 'id', title: '配件编号', width:120, align:'center'}
                ,{field: 'purchasetime', title: '配件名称',sort: true, minWidth:130,align:'center',templet: '#timeFormat'}
                ,{field: 'summoney', title: '车型',sort: true, width:110,align:'center'}
                ,{field: 'favorable', title: '产地',sort: true, minWidth:110,align:'center'}
                ,{field: 'payamount', title: '单位', minWidth: 110, sort: true,align:'center'}
                ,{field: 'grade', title: '库存', minWidth:80,align:'center',templet:'#priceGrade'}
                ,{field: 'status', title: '数量', minWidth:80, align:'center',templet:'#verifyStatus'}
                ,{field: 'status', title: '单价', minWidth:80, align:'center',templet:'#verifyStatus'}
                ,{field: 'status', title: '金额', minWidth:80, align:'center',templet:'#verifyStatus'}
                ,{field: 'status', title: '备注', minWidth:80, align:'center',templet:'#verifyStatus'}
                ,{title: '操作', width: 200, templet: '#operator', align:'center'}
            ]]
            ,id:'testReload'
        });

        var $ = layui.$, active = {
            reload: function(){
                var demoReload = $('#demoReload');

                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        //key: {
                        id: demoReload.val()
                        //}
                    }
                });
            }
        };

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        /*$('#delLog').on('click',function (obj) {
            layer.confirm('真的删除行么', function(index){
                obj.getCheckData();
                layer.close(index);
            });
        })*/

        form.on('select(myselect)', function(data){
           console.log(data.value);
            var val=data.value;
            if(val!='请选择'){
                var arr=val.split(",");
                $('#payment').val(arr[1]);
                $(this).val(arr[0]);
            }
           /* var areaId=(data.value).replaceAll(",","");
            $.ajax({
                type: 'POST',
                url: '/shopInfo/findCity',
                data: {areaId:areaId},
                dataType:  'json',
                success: function(data){
                    $("#City").html("");
                    $.each(data, function(key, val) {
                        var option1 = $("<option>").val(val.areaId).text(val.fullname);
                        $("#City").append(option1);
                        form.render('select');
                    });
                    $("#City").get(0).selectedIndex=0;
                }
            });*/
        });
    });
    function initSelect(){
        $('#supplier').empty();
        $('#supplier').append('<option value="">请选择</option>');
        //Ajax调用处理
        $.ajax({
            type: "POST",
            url: "/supplier/getList",
            //data: "name=garfield&age=18",
            async:false,
            success: function(result){
                var data=result.list;
                var option='';
                if(data.length>0){
                    for (var i=0;i<data.length;i++){
                        option+='<option value="'+data[i].id+','+data[i].payment+'">'+data[i].name+'</option>';
                    }
                }
                $('#supplier').append(option);
                $("#supplier").get(0).selectedIndex=0;
                //form.render('select');
            }
        });

    }


</script>
<script type="text/html" id="timeFormat">
    {{ dateFormat1(d.purchasetime) }}
</script>
<script type="text/html" id="levelType">
    {{ formatLevelType(d.logLevel)}}
</script>
<script type="text/html" id="priceGrade">
    {{#  if(d.grade ===2){ }}
    记忆价
    {{#  } else { }}
    默认价
    {{#  } }}
</script>
<script type="text/html" id="verifyStatus">
    {{#  if(d.status ===1){ }}
    已审核
    {{#  } else { }}
    未审核
    {{#  } }}
</script>
<script type="text/html" id="operator">
    {{#  if(d.status ===1){ }}
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
    {{#  } else { }}
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="verify">审核</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    {{#  } }}
</script>

<script type="text/html" id="unPay">
    {{d.summoney-d.favorable-d.payamount}}
</script>
<script type="text/html" id="parseSupplier">
    {{#  if(d.supplier!=null){ }}
    {{d.supplier.name}}
    {{#  } else { }}
    无数据
    {{#  } }}
</script>

</body>
</html>
